package 算法.leetcode.labuladong.数组和链表;

/**
 * https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/
 * @author lchenglong
 * @date 2022/6/16
 */
public class 两数之和II之输入有序数组 {
    class Solution {
        public int[] twoSum(int[] numbers, int target) {
            int left = 0,right = numbers.length-1;
            while (left<right){
                int sum = numbers[left] +numbers[right];
                if (sum == target){
                    return new int[]{left+1,right+1};
                } else if (sum<target){
                    // 让 sum大一点
                    left++;
                } else {
                    // 让sum小一点
                    right--;
                }
            }
            return new int[]{-1,-1};
        }
    }
}
